#ifndef __READER_H__
#define __READER_H__

#include "gd32e23x.h"

typedef struct SReader TReader;

// FuncRead ??????
typedef uint16_t ( *FuncCard ) ( uint8_t * ACardSN );
typedef uint16_t ( *FuncCmd ) ();

// ??????????�???CPU
extern volatile uint8_t GCPUCard;
extern uint8_t G_Error_Count;

uint8_t GetCardArea ( uint8_t sector, uint8_t block );

typedef struct SPurse
{
    uint8_t EmbedSN[4];		
    uint16_t CardType;      // 卡片类型
    uint16_t AuthCode;      // ??????
    uint16_t Num;         // ????�
    uint32_t Balance;     // 余额
    uint16_t TradeSerial; // ??????
    uint8_t DateUsage;
    uint8_t Date;
    uint8_t Month;
    uint16_t MonthUsage;
    uint16_t DayLimitAmo;
} TPurse;

// SReader 用户
struct SReader
{
    TPurse Purse;		// { ?????? }
    FuncCard Find;	// { ?????? }
    FuncCard ReadNum;	// { ????�????�???????� }
    FuncCmd ReadMoney;	// { ?????�� }
    uint16_t (*PrepaySmall) (uint16_t Amount, uint8_t IsFirst);	// { ??�?�???� }
    uint16_t (*FreePaySmall)(uint16_t Amount, uint8_t IsFirst);	// { ??�?�???� }
//    Proc WaitOver;	 // { ?????????????� }
    char (*HaltCard)(void);
};

// Reader ???????�
extern volatile TReader Reader;
// GCardOn ?�????????????
extern volatile uint8_t GCardOn;
// GOperOn ?�??????????�
extern volatile uint8_t GOperOn;
extern volatile uint8_t GNumBlock[16];
extern uint16_t oType;

TReader *NewReader();
uint16_t CheckM1Card (void);
uint16_t CheckCpuCard (void);

void CheckCardOn (void);

#endif

